package com.wenhai.concurrency.thread.pool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName ThreadPoolExecutorDemo
 * @Description
 * @Author 谢文海
 * @Date 2021/4/24 0:46
 * @Version 1.0
 **/
public class ThreadPoolExecutorDemo {
    public static void main(String[] args) throws InterruptedException {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5, 7, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<>(4));
        threadPoolExecutor.allowCoreThreadTimeOut(true);
        for (int i = 0; i < 10; i++) {
            threadPoolExecutor.execute(()->
                    System.out.printf("当前时间为：%s,当前线程：%s\n", System.nanoTime(), Thread.currentThread().getName())
            );
        }
        System.out.println(threadPoolExecutor.getCorePoolSize() +" "+ threadPoolExecutor.getPoolSize());
        TimeUnit.SECONDS.sleep(3);
        System.out.println(threadPoolExecutor.getCorePoolSize() +" "+ threadPoolExecutor.getPoolSize());
    }
}
